package com.neusoft.neuiotms.dcom.converter.incident;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.incident.IncidentHandleAttachmentDTO;
import com.neusoft.neuiotms.dcom.model.incident.IncidentHandleAttachment;
import com.neusoft.neuiotms.dcom.repository.incident.IncidentHandleAttachmentRepository;

@Component
public class IncidentHandleAttachmentConverter
        extends AbstractConverter<IncidentHandleAttachment, IncidentHandleAttachmentDTO> {

    @Autowired
    private IncidentHandleAttachmentRepository incidentHandleAttachmentRepository;

    @Override
    public IncidentHandleAttachment toModel(final IncidentHandleAttachmentDTO dto) {
        IncidentHandleAttachment model;
        if (dto.isNew()) {
            model = new IncidentHandleAttachment();
        } else {
            model = this.incidentHandleAttachmentRepository.getOne(dto.getId());
        }
        model.setFsId(dto.getFsId());
        model.setName(dto.getName());
        return model;
    }

    @Override
    public IncidentHandleAttachmentDTO toDTO(final IncidentHandleAttachment model, final boolean forListView) {
        final IncidentHandleAttachmentDTO dto = new IncidentHandleAttachmentDTO();
        dto.setFsId(model.getFsId());
        dto.setId(model.getId());
        dto.setName(model.getName());
        return dto;
    }

}
